function fsb_mat_write(idat,fileName,header,m)

% FSB :  write mat files to disk
%
% EXAMPLE:
% fsb_mat_write(idat,fileName,header_template,typ_e,gopt)
%
% INPUT:
% fileName: Name of file to write
% idat :     4-D image dataset or string for dataset size information
% header: template header file name or struct
% m: explicit mat file information
%
% OUTPUT:
% .mat files for SPM spatial transforms
%
% CALLED BY:
% FSB.m
% fsb_export.m
% fsb_prepare_SPM.m
% fsb_realign_SPM.m
% fsb_SPM5.m
% fsb_SPM.m
%
% NOTES:
% In development
%
% Steffen Stoewer 2007 stoewer@tuebingen.mpg.de
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
%
% $Revision 1.0
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Write images
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if nargin<4


    M(1,:) = sandbox.hdr.hist.srow_x;
    M(2,:) = sandbox.hdr.hist.srow_y;
    M(3,:) = sandbox.hdr.hist.srow_z;
    M(4,:) = [0 0 0 1];
    File_Name = [fileName '.mat']

    save(File_Name,'M')

else

    M = m
    File_Name = [fileName '.mat']

    save(File_Name,'M')

end

end